package com.example.aipdefficiency.controller;

import com.example.aipdefficiency.common.ApiResponse;
import com.example.aipdefficiency.service.VerifyCodeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.constraints.Pattern;

@Slf4j
@RestController
@RequestMapping("/v1/verify-code")
@Tag(name = "验证码管理", description = "验证码相关接口")
public class VerifyCodeController {
    
    @Autowired
    private VerifyCodeService verifyCodeService;
    
    @PostMapping("/send")
    @Operation(summary = "发送验证码", description = "向指定手机号发送验证码")
    public ApiResponse<String> sendVerifyCode(
            @Parameter(description = "手机号", required = true, example = "18888888888")
            @Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式不正确")
            @RequestParam String mobile) {
        
        log.info("发送验证码请求，手机号: {}", mobile);
        String verifyCode = verifyCodeService.generateAndSendVerifyCode(mobile);
        
        // 在开发环境返回验证码，生产环境不应该返回
        return ApiResponse.success("验证码发送成功", verifyCode);
    }
} 